package com.solomon.travel.common.front.controller;

import java.util.List;

import javax.annotation.Resource;

import org.aspectj.weaver.ast.IExprVisitor;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.solomon.travel.common.base.controller.BaseController;
import com.solomon.travel.common.model.ApiResponse;
import com.solomon.travel.common.model.Page;
import com.solomon.travel.common.po.Hotel;
import com.solomon.travel.common.service.HotelService;
import com.solomon.travel.common.util.ConstantUtils;
import com.solomon.travel.common.util.PageUtils;

@RestController("frontHotelController")
@RequestMapping("/front/hotel")
public class HotelController extends BaseController{
	
	@Resource
	private HotelService hotelService;
	
	@RequestMapping("/list/home")
	public ApiResponse listByHome() throws Exception {
		Page page = new Page();
		page.setBeginIndex(0);
		page.setPageSize(6);
		List<Hotel> hotels = hotelService.listHotel(page);
		return new ApiResponse(ConstantUtils.RESPONSE_CODE_OK, hotels);
	}
	
	@RequestMapping("/list")
	public ApiResponse list(Integer pageIndex,Integer pageSize,Hotel hotel)throws Exception {
		int minRoomNum = 0;
		int maxRoomNum = 0;
		if(hotel.getRoomNum() != null){
		switch (hotel.getRoomNum()) {
		case 0:
			minRoomNum = 1;
			maxRoomNum = 10;
			break;
		case 1:
			minRoomNum = 11;
			maxRoomNum = 20;
		break;
		case 2:
			minRoomNum = 21;
			maxRoomNum = 30;
			break;
		case 3:
			minRoomNum = 31;
			maxRoomNum = 40;
			break;
		case 4:
			minRoomNum = 41;
			maxRoomNum = 50;
			break;
		case 5:
			minRoomNum = 51;
			break;
		default:
			break;
		}
		}
		
		int hotelCount = hotelService.countBySerch(hotel, minRoomNum, maxRoomNum);
		Page page = PageUtils.createPage(pageSize, hotelCount, pageIndex);
		List<Hotel> hotels = hotelService.listBySerch(hotel, minRoomNum, maxRoomNum, page);
		return new ApiResponse(ConstantUtils.RESPONSE_CODE_OK, hotels,page);
	}
}
